﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace X3DXNA.services
{
    class myBasicEffect
    {

        #region Private Fields

        BasicEffect basicEffect;

        #endregion

        #region Public Properties

        public BasicEffect getBasicEffect { get { return basicEffect; } }

        public Matrix world
        {
            get { return basicEffect.World; }
            set { basicEffect.World = value; }
        }
        public Matrix view
        {
            get { return basicEffect.View; }
            set { basicEffect.View = value; }
        }
        public Matrix projection
        {
            get { return basicEffect.Projection; }
            set { basicEffect.Projection = value; }
        }
        public Vector3 DiffuseColor
        {
            get { return basicEffect.DiffuseColor; }
            set { basicEffect.DiffuseColor = value; }
        }
        public Vector3 EmissiveColor
        {
            get { return basicEffect.EmissiveColor; }
            set { basicEffect.EmissiveColor = value; }
        }
        public Vector3 SpecularColor
        {
            get { return basicEffect.SpecularColor; }
            set { basicEffect.SpecularColor = value; }
        }
        public float Alpha
        {
            get { return basicEffect.Alpha; }
            set { basicEffect.Alpha = value; }
        }

        #endregion

        #region Constructor

        public myBasicEffect(Game1 game, GraphicsDeviceManager graphics)
        {
            game.Services.AddService(typeof(myBasicEffect), this);

            basicEffect = new BasicEffect(graphics.GraphicsDevice);
            
            // primitive color
            //basicEffect.AmbientLightColor = new Vector3(0.2f, 0.2f, 0.2f);
            //basicEffect.DiffuseColor = new Vector3(1.0f, 1.0f, 1.0f);
            //basicEffect.SpecularColor = new Vector3(0.25f, 0.25f, 0.25f);
            //basicEffect.SpecularPower = 5.0f;
            //basicEffect.Alpha = 1.0f;
            //basicEffect.VertexColorEnabled = true;

            basicEffect.PreferPerPixelLighting = true;

            basicEffect.EnableDefaultLighting();

            //basicEffect.LightingEnabled = true;

            if (basicEffect.LightingEnabled && false)
            {
                basicEffect.DirectionalLight0.Enabled = true; // enable each light individually
                if (basicEffect.DirectionalLight0.Enabled)
                {
                    // x direction
                    basicEffect.DirectionalLight0.DiffuseColor = new Vector3(1, 1, 1); // range is 0 to 1
                    basicEffect.DirectionalLight0.Direction = Vector3.Normalize(new Vector3(-1, 0, 0));
                    // points from the light to the origin of the scene
                    basicEffect.DirectionalLight0.SpecularColor = Vector3.One;
                }

                basicEffect.DirectionalLight1.Enabled = true;
                if (basicEffect.DirectionalLight1.Enabled)
                {
                    // y direction
                    basicEffect.DirectionalLight1.DiffuseColor = new Vector3(1, 1, 1);
                    basicEffect.DirectionalLight1.Direction = Vector3.Normalize(new Vector3(0, -1, 0));
                    basicEffect.DirectionalLight1.SpecularColor = Vector3.One;
                }

                basicEffect.DirectionalLight2.Enabled = true;
                if (basicEffect.DirectionalLight2.Enabled)
                {
                    // z direction
                    basicEffect.DirectionalLight2.DiffuseColor = new Vector3(1, 1, 1);
                    basicEffect.DirectionalLight2.Direction = Vector3.Normalize(new Vector3(0, 0, -1));
                    basicEffect.DirectionalLight2.SpecularColor = Vector3.One;
                }
            }

        }

        #endregion
    }
}
